<template>
  <div ref="container">
    <breadcrumb :breadList="breadList" :name="name">
      <div class="handle-box" slot="handleContent">
        <div class="handle-btn">
          <a-button class="common-btn" @click="go_toOperation('create', '')">添加人员</a-button>
        </div>
        <div class="handle-btn">
          <a-button class="common-btn" @click="importList">批量导入</a-button>
        </div>
        <div class="handle-btn">
          <a-button class="common-btn" @click="exportList">导出列表</a-button>
        </div>
      </div>
    </breadcrumb>
    <a-card>
      <a-form @submit="handleSubmit" :form="form">
        <a-row clss="form-row" :gutter="16">
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="人员姓名" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
              <a-input v-model="queryParam.name" placeholder="人员姓名"/>
            </a-form-item>
          </a-col>
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="当前状态" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
              <a-textarea v-model="queryParam.status" rows="1" placeholder="当前状态"/>
            </a-form-item>
          </a-col>
          <a-col :lg="2" :md="12" :sm="24">
            <a-form-item label="" :colon="false">
              <a-button class="common-btn" @click="toSearch('2')">查询</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card>
      <a-table
        :columns="columns"
        :dataSource="loadData"
        bordered
        :loading="loading"
        :pagination="false"
        :scroll="{ x: 1150 }">
        <template slot="operation" slot-scope="text, record">
          <p style="display:inline" @click="$refs.dispatchModel.add(record)">
            <a href="javascript:;">人工派单</a>
            <a-divider type="vertical"/>
          </p>
          <p style="display:inline" @click="sendMessage(record)">
            <a href="javascript:;">发送信息</a>
            <a-divider type="vertical"/>
          </p>
          <p style="display:inline" @click="go_toOperation('modify',record)">
            <a href="javascript:;">编辑</a>
            <a-divider type="vertical"/>
          </p>
          <p style="display:inline" @click="go_toOperation('detail',record)">
            <a href="javascript:;">详情</a>
          </p>
        </template>
      </a-table>
      <dispatch-model ref="dispatchModel" @closeModel="closeModel"></dispatch-model>
    </a-card>
  </div>
</template>

<script>
import Breadcrumb from '@/components/tools/Breadcrumb'
import DispatchModel from './dispatchModel'
// import { getSupplierList } from '@/api/mockdata'
export default {
  name: 'SupplierManagementList',
  components: {
    Breadcrumb,
    DispatchModel
  },
  data () {
    return {
      name: '',
      breadList: [],
      loading: false,
      form: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '姓名',
          width: '7%',
          dataIndex: 'name'
        }, {
          title: '所属部门',
          width: '10%',
          dataIndex: 'department'
        }, {
          title: '性别',
          width: '7%',
          dataIndex: 'sex'
        }, {
          title: '人员编号',
          width: '10%',
          dataIndex: 'personCode'
        }, {
          title: '联系电话',
          width: '12%',
          dataIndex: 'tel'
        },
        {
          title: '当前状态',
          width: '10%',
          dataIndex: 'cunrrentStatus'
        },
        {
          title: '上次接单时间',
          width: '12%',
          dataIndex: 'lastTime'
        },
        {
          title: '累计接单量',
          width: '10%',
          dataIndex: 'totalNum'
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: []
    }
  },
  created () {
    this.loading = true
    this.getBreadCrumb()
    setTimeout(() => {
      this.getData('1')
    }, 1000)
  },
  methods: {
    // 面包屑处理
    getBreadCrumb () {
      this.breadList = []
      this.name = this.$route.name
      this.$route.matched.forEach(item => {
        console.log('1111', item)
        this.breadList.push(item)
      })
    },
    getData (code) {
      const data = [
        {
          name: '张三',
          department: '维修部',
          sex: '男',
          personCode: 'wx-001',
          tel: '18899999999',
          cunrrentStatus: '在职',
          lastTime: '2015-12-30',
          totalNum: '199'
        }, {
          name: '张三',
          department: '维修部',
          sex: '男',
          personCode: 'wx-001',
          tel: '18899999999',
          cunrrentStatus: '在职',
          lastTime: '2015-12-30',
          totalNum: '199'
        }, {
          name: '张三',
          department: '维修部',
          sex: '男',
          personCode: 'wx-001',
          tel: '18899999999',
          cunrrentStatus: '在职',
          lastTime: '2015-12-30',
          totalNum: '199'
        }, {
          name: '张三',
          department: '维修部',
          sex: '男',
          personCode: 'wx-001',
          tel: '18899999999',
          cunrrentStatus: '在职',
          lastTime: '2015-12-30',
          totalNum: '199'
        }, {
          name: '张三',
          department: '维修部',
          sex: '男',
          personCode: 'wx-001',
          tel: '18899999999',
          cunrrentStatus: '在职',
          lastTime: '2015-12-30',
          totalNum: '199'
        }, {
          name: '张三',
          department: '维修部',
          sex: '男',
          personCode: 'wx-001',
          tel: '18899999999',
          cunrrentStatus: '在职',
          lastTime: '2015-12-30',
          totalNum: '199'
        }
      ]
      if (code === '1') {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
        }, 1000)
      } else {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
          this.$success({
            title: '查询成功'
          })
        }, 1000)
      }
    },
    toSearch (status) {
      this.loading = true
      this.getData(status)
    },
    handleSubmit () {
      console.log('ttt')
    },
    importList () {
      this.$success({
        title: '导入成功'
      })
    },
    exportList () {
      this.$success({
        title: '导出成功'
      })
    },
    closeModel () {
      this.getData('2')
    },
    sendMessage () {
      const that = this
      this.$confirm({
        title: '确认给此人员发送消息吗',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '发送成功'
          })
        }
      })
    },
    go_toOperation (type, record) {
      console.log('========', record)
      // if (type !== 'create' && type !== 'modify') {
      //   this.$router.push({
      //     name: 'proDetails',
      //     query: {
      //       proDetails: JSON.stringify(record)
      //     }
      //   })
      // } else {
      this.$router.push({
        name: 'addPersonnel',
        query: {
          type: type,
          proDetails: JSON.stringify(record)
        }
      })
      // }
    }
  }
}

</script>

<style lang="less" scoped>
// .handle-box {
//   display: flex;
//   margin-bottom: 10px;
//   margin-left: 800px;
// }
// .handle-btn {
//   margin-left:5px;
// }
</style>
